/**
 * @(#) MethodComponent.java
 */

package cn.edu.sjtu.se.dslab.component.method;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import cn.edu.sjtu.se.dslab.component.Component;
import cn.edu.sjtu.se.dslab.project.Project;

@Entity
@Table(name = "method_component")
@PrimaryKeyJoinColumn(name = "id")
public class MethodComponent extends Component {
	private static final long serialVersionUID = 1L;

	private String implement;

	/**
	 * 可以有多个文件，以分号隔开(表示依赖的文件，目前暂未保留字段)
	 */
	private String filePath;
	
	/**
	 * 功能函数组件的类型---暂为保留字段
	 */
	private String methodType;

	/***
	 * 依赖于其他的component
	 */
	private Set<MethodComponent> depends;

	/***
	 * 依赖于当前component的其他component
	 */
	private Set<MethodComponent> childList;
	
	private ComponentInterface cinterface;
	
	private String headerFile;
	
	private String srcFile;

	/**
	 * 特别绑定至某个project的methodcomponent，不用于检索
	 */
	private Project project;
	
	
	
	@Column(name = "file_paths", nullable = true, length = 10000)
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	@Lob
	@Column(name = "implement", columnDefinition = "TEXT", nullable = true)
	public String getImplement() {
		return implement;
	}

	public void setImplement(String implement) {
		this.implement = implement;
	}

	@Column(name = "header_file", nullable = true, length = 2000)
	public String getHeaderFile() {
		return headerFile;
	}

	public void setHeaderFile(String headerFile) {
		this.headerFile = headerFile;
	}

	
	@Column(name = "method_type", nullable = true, length = 255)
	public String getMethodType() {
		return methodType;
	}

	public void setMethodType(String methodType) {
		this.methodType = methodType;
	}

	@Column(name = "src_file", nullable = true, length = 2000)
	public String getSrcFile() {
		return srcFile;
	}

	public void setSrcFile(String srcFile) {
		this.srcFile = srcFile;
	}


	
	@ManyToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "project_id",nullable = true)
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	// 多对多处理
	// @ManyToMany(cascade={CascadeType.ALL})
	@ManyToMany(targetEntity = cn.edu.sjtu.se.dslab.component.method.MethodComponent.class, cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinTable(name = "method_dependence", joinColumns = @JoinColumn(name = "child_id"), inverseJoinColumns = @JoinColumn(name = "parent_id"))
	public Set<MethodComponent> getDepends() {
		return depends;
	}
	

	public void setDepends(Set<MethodComponent> depends) {
		this.depends = depends;
	}

	// @ManyToMany(mappedBy = "depends")
	@ManyToMany(cascade = { CascadeType.ALL }, mappedBy = "depends", targetEntity = cn.edu.sjtu.se.dslab.component.method.MethodComponent.class, fetch = FetchType.EAGER)
	public Set<MethodComponent> getChildList() {
		return childList;
	}

	public void setChildList(Set<MethodComponent> childList) {
		this.childList = childList;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "interface_id")
	public ComponentInterface getCinterface() {
		return cinterface;
	}

	public void setCinterface(ComponentInterface cinterface) {
		this.cinterface = cinterface;
	}

}
